home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
workbench
/
tools
/
czesc_1
/
executive_v1.00
/
sysinfo.lzx
/
sysinfo.doc
< prev
Wrap
Text File
|
1990-07-25
|
21KB
|
666 lines
TABLE OF CONTENTS
sysinfo.library/--background--
sysinfo.library/AddNotify
sysinfo.library/FreeSysinfo
sysinfo.library/GetCpuUsage
sysinfo.library/GetLoadAverage
sysinfo.library/GetNice
sysinfo.library/GetPgrp
sysinfo.library/GetPid
sysinfo.library/GetPpid
sysinfo.library/GetTaskCpuUsage
sysinfo.library/InitSysinfo
sysinfo.library/RemoveNotify
sysinfo.library/SetNice
sysinfo.library/--background-- sysinfo.library/--background--
PURPOSE
Sysinfo.library was developed to bring together all the different
utility programs that add some new features to Amiga task
handling, like CPU usage calculation. Sysinfo.library was first
developed for Executive, but it's possible to rewrite it to
support other similar programs. It's not necessary to support
all sysinfo.library functions in all implementations.
OVERVIEW
Currently supported features
* CPU usage
Sysinfo.library provides several CPU usage indicators, e.g.
total used CPU time, CPU time used during last second,
recently used CPU time. Executive will also provide context
switch counters.
* load averages
Load average is the number of tasks ready or running over various
periods of time, usually 1, 5 and 15 minutes. A load average 1.0
means that there has been exactly one task running.
* PID, PPID and PGRP
PID is a process identifier. This is a unique number assigned for
each task in the system.
PPID is a parent process identifier. It's the PID of the process
that has created the current process.
PGRP is a process group. Process groups can't be implemented on
Amiga at the moment, because it's impossible to distinguish
if a task is a child-task or a totally separate task. In Executive
process groups mean processes created by a specific task. The
PGRP number is the PID of the parent task. By referring to a specific
process group, you refer to all tasks created by the parent task.
* nice-values
Nice-values similar to Amiga priorities, they are used by the
scheduler when calculating priorities for different tasks.
NOTES
If some function can't be implemented, a valid error-value
should still be returned.
A `server' in this document means the program calculating all
this information. Sysinfo.library is a standard interface to
different servers.
AUTHOR
Petri Nordlund <petrin@mits.mdata.fi> or <petrin@sik.ppoy.fi>
HISTORY
V1.00 First release
FUTURE
Here are some functions which could be included in sysinfo.library:
acct
getegid
geteuid
getgid
getgroups
getlogin
getrlimit
getrusage
getuid
setegid
seteuid
setgid
setgroups
setlogin
setpgrp
setpgid
setrlimit
setsid
setuid
sysinfo.library/AddNotify sysinfo.library/AddNotify
NAME
AddNotify - Add a notification request
SYNOPSIS
sysinfo_notify = AddNotify(sysinfo,use_messages,safety_limit);
D0 A0 D0 D1
struct sysinfo_notify *AddNotify(struct sysinfo *, BOOL, ULONG);
FUNCTION
Ask the server to notify us after it has updated it's information.
After the notification, new load average, CPU usage and other
information may be requested and they'll be up-to-date. Notification
is useful if your application updates it's display frequently.
You don't end up updating just before the server will calculate
new information. The notification will keep your application in sync
with the server.
There are two ways to notify your task, by signals or messages.
Signals are very fast, but they don't queue. The safety_limit
variable can be used with messages, it's the maximum number of
notification messages that will be sent to you before you reply
to them. A good value here is about 10 - 20.
This function returns a sysinfo_notify structure, which you
must not modify. If you use messages for notification, it has
a pointer to a port where the messages will arrive. Just reply
to the messages you get. There may be some internal information
in these messages that the server will use so don't modify them.
If you have ask for signals to be used for notification, there
will be a signal number in the structure. Just Wait() for that
signal.
Before requesting notification, make sure that it's implemented.
The sysinfo->notify_sig_implemented is TRUE if you can use
signals and the sysinfo->notify_msg_implemented is TRUE if
notification with messages is available.
A notification happens once every second.
INPUTS
sysinfo - sysinfo structure returned by InitSysinfo()
use_messages - TRUE to use messages, FALSE to use signals
safety_limit - maximum number of messages sent to you
RESULT
sysinfo_notify - a structure defined in <libraries/sysinfo.h> or
NULL if there was an error
BUGS
SEE ALSO
RemoveNotify(), <libraries/sysinfo.h>
sysinfo.library/FreeSysinfo sysinfo.library/FreeSysinfo
NAME
FreeSysinfo - Finish using the sysinfo.library
SYNOPSIS
FreeSysinfo(sysinfo);
A0
void FreeSysinfo(struct sysinfo *);
FUNCTION
Declares that you are finished using the services provided by
sysinfo.library. The sysinfo structure will be freed.
INPUTS
sysinfo - structure returned by InitSysinfo()
RESULT
None
BUGS
SEE ALSO
InitSysinfo(), <libraries/sysinfo.h>
sysinfo.library/GetCpuUsage sysinfo.library/GetCpuUsage
NAME
GetCpuUsage - Get the current CPU usage values
SYNOPSIS
GetCpuUsage(sysinfo, cpu_usage);
A0 A1
void GetCpuUsage(struct sysinfo *, struct cpu_usage *);
FUNCTION
The cpu_usage structure will be filled with current CPU usage
values.
The sysinfo->cpu_usage_implemented field indicates what values
are implemented in the sysinfo.library. The corresponding
bits are defined in <libraries/sysinfo.h>:
CPU_USAGEF_TOTAL_IMPLEMENTED
Total CPU usage. The cpu_usage->total_used_cputime is the CPU time
used in seconds. The cpu_usage->total_elapsed_time is the used
cputime plus idle CPU time, i.e. the elapsed time since CPU time
calculations began. You can calculate the CPU usage percentage
in this way:
100 * total_used_cputime / total_elapsed_time
CPU_USAGEF_LASTSEC_IMPLEMENTED
CPU time used by all processes during last second. The
cpu_usage->used_cputime_lastsec_hz is the number of clock
ticks during one second. The cpu_usage->used_cputime_lastsec
is the number of ticks used. To calculate the percentage
of CPU time used:
100 * used_cputime_lastsec / used_cputime_lastsec_hz
CPU_USAGEF_RECENT_IMPLEMENTED
The cpu_usage->recent_used_cputime is a decaying average of
recent CPU usage. In Executive this is for the last minute.
The time in seconds is stored in cpu_usage->recent_seconds.
You can calculate recent CPU usage percentage in this way:
100 * recent_used_cputime / recent_used_cputime_hz
CPU_USAGEF_IVVOCSW_IMPLEMENTED
Some servers can also keep a count of the number of context
switches. A context switch happens when one task is switched
to another. The cpu_usage->involuntary_csw field indicates the
total number of involuntary context switches and the
cpu_usage->voluntary_csw field indicates the total number of
voluntary context switches.
Involuntary context switch happens when the CPU is taken
away from a task that has not finished using it. This happens
when a higher priority task becomes ready to run.
Voluntary context switch happens when task calls Wait() and
a lower priority task gets CPU time.
CPU_USAGEF_TOTALCSW_IMPLEMENTED
In some implementations only the total number of context switches
is available. The cpu_usage->total_csw is just involuntary context
switches plus voluntary context switches, if specific information
is available.
CPU_USAGEF_IVVOCSW_LASTSEC_IMPLEMENTED
CPU_USAGEF_TOTALCSW_LASTSEC_IMPLEMENTED
Like above, but for the last second.
When using these numbers, do all calculations in 32-bits.
INPUTS
sysinfo - structure returned by InitSysinfo()
cpu_usage - structure defined in <libraries/sysinfo.h>
RESULT
None
BUGS
SEE ALSO
GetTaskCpuUsage(), <libraries/sysinfo.h>
sysinfo.library/GetLoadAverage sysinfo.library/GetLoadAverage
NAME
GetLoadAverage - Get load averages
SYNOPSIS
GetLoadAverage(sysinfo, loadaverage);
A0 A1
void GetLoadAverage(struct sysinfo *, struct loadaverage *);
FUNCTION
This function fills the loadaverage structure with current load
average values. There are three values which mean the average
load for the last few minutes. Usually these are 1, 5 and 15
minutes, but it may vary. The number of seconds each load average
means, is stored in sysinfo->loadavg_time[1-3]. The number 0 means
that the load average for that time is not implemented.
The sysinfo->loadavg_type field indicates the way the load averages
are stored in the loadaverage structure. This can be LOADAVG_NONE,
in which case the load averages are not available at all.
LOADAVG_FIXEDPNT means that the load averages are stored as
32-bit values that have been multiplied with sysinfo->fscale.
To get the actual load average, you need to calculate in floating
point numbers:
(float) loadaverage->loadaverage.lavg_fixed.load1 / (float) sysinfo->fscale
If the loadavg_type is LOADAVG_FLOAT, then the load average values
are in floating point numbers, for example:
loadaverage->loadaverage.lavg_float.load1
INPUTS
sysinfo - structure returned by InitSysinfo()
loadaverage - structure defined in <libraries/sysinfo.h>
RESULT
None
BUGS
SEE ALSO
<libraries/sysinfo.h>
sysinfo.library/GetNice sysinfo.library/GetNice
NAME
GetNice - get internal priority, nice-value
SYNOPSIS
nice = GetNice(sysinfo, which, who)
D0 A0 D0 D1
int GetNice(struct sysinfo *, int, int);
FUNCTION
Get a nice-value for a process or group of processes. Nice-value
is used when the server also contains a scheduler, like Executive.
Nice-value is used when calculating scheduling priorities for tasks.
The nice-value that gives most CPU time is available from
sysinfo->nicemin (usually -20) and the nice-value that gives
least CPU time is in sysinfo->nicemax (usually +20).
Which is one of PRIO_PROCESS, PRIO_PGRP, PRIO USER or PRIO_TASK and
who is interpreted relative to which (a process identifier for
PRIO_PROCESS, process group identifier for PRIO_PGRP, user ID
for PRIO_USER and a task address for PRIO_TASK). A zero value of
who denotes the current process, process group, user or task. Prio
is a value in the range sysinfo->nicemin to sysinfo->nicemax.
The GetNice() call returns the highest nice-value (usually lowest
numerical value) enjoyed by any of the specified processes.
Bits in sysinfo->which_implemented indicate what values you can
use for which. If this value is 0, then GetNice() and SetNice()
routines are not available.
INPUTS
sysinfo - structure returned by InitSysinfo()
which - get priority from which processes
who - depends on which-field, 0 means current process, PGRP, user or task
RESULT
nice - highest nice-value enjoyed by any of the specified processes
-1 is returned if an error occurs. Since -1 is a legitimate
value, it is necessary to look at sysinfo->errno value if
-1 is returned by GetNice(). If errno is zero, no error has
occurred otherwise it will be one of these:
WHICH_ESRCH No process was located using the which and who values
specified.
WHICH_EINVAL Which was not one of PRIO_PROCESS, PRIO_PGRP,
PRIO_USER or PRIO_TASK, or that value is not supported.
NOTES
The name of this function should have been GetPriority() like in
Un*x, but it might have been confused with Exec priorities.
BUGS
SEE ALSO
<libraries/sysinfo.h>
sysinfo.library/GetPgrp sysinfo.library/GetPgrp
NAME
GetPgrp - Get a process group identifier
SYNOPSIS
pgrp = GetPgrp(sysinfo);
D0 A0
int GetPgrp(struct sysinfo *);
FUNCTION
The process group of the current process is returned by GetPgrp().
If this function is available, the sysinfo->GetPgrp_implemented field
is TRUE.
INPUTS
sysinfo - structure returned by InitSysinfo()
RESULT
pgrp - process group identifier or -1 if process group is unknown
BUGS
SEE ALSO
GetPid(), GetPpid(), <libraries/sysinfo.h>
sysinfo.library/GetPid sysinfo.library/GetPid
NAME
GetPid - Get a process identifier
SYNOPSIS
pid = GetPid(sysinfo);
D0 A0
int GetPid(struct sysinfo *);
FUNCTION
GetPid() returns the process ID of the calling task. The ID is
guaranteed to be unique and is useful for constructing temporary
file names.
This routine is always available. If special unique PIDs can't
be given, it return the task address, so calling this is equivalent
to calling FindTask(NULL).
INPUTS
sysinfo - structure returned by InitSysinfo()
RESULT
pid - process identifier
BUGS
SEE ALSO
GetPgrp(), GetPpid(), <libraries/sysinfo.h>
sysinfo.library/GetPpid sysinfo.library/GetPpid
NAME
GetPpid - Get a parent process identifier
SYNOPSIS
pid = GetPpid(sysinfo);
D0 A0
int GetPpid(struct sysinfo *);
FUNCTION
GetPpid() returns the process ID of the parent of the calling task.
If this function is available, the sysinfo->GetPpid_implemented field
is TRUE.
INPUTS
sysinfo - structure returned by InitSysinfo()
RESULT
pid - parent process identifier or -1 if parent is unknown
BUGS
SEE ALSO
GetPgrp(), GetPid(), <libraries/sysinfo.h>
sysinfo.library/GetTaskCpuUsage sysinfo.library/GetTaskCpuUsage
NAME
GetCpuUsage - Get the current CPU usage values for a task
SYNOPSIS
success = GetTaskCpuUsage(sysinfo, task_cpu_usage, task);
D0 A0 A1 A2
int GetTaskCpuUsage(struct sysinfo *, struct task_cpu_usage *, struct Task *);
FUNCTION
The cpu_usage structure will be filled with current CPU usage
values for the specified task. Specify NULL for current task.
This routine is rather similar to GetCpuUsage, but has some
small differences.
The sysinfo->task_cpu_usage_implemented field indicates what
values are implemented in the sysinfo.library. The corresponding
bits are defined in <libraries/sysinfo.h>:
TASK_CPU_USAGEF_TOTAL_IMPLEMENTED
Total CPU usage. The task_cpu_usage->total_used_time_hz is the
number of clock ticks during one second. The task_cpu_usage->
total_used_cputime is the total number of ticks used. You can
calculate the CPU usage percentage in this way:
100 * total_used_cputime / total_used_time_hz
The task_cpu_usage->total_elapsed_time is the used CPU time plus
idle CPU time, i.e. the elapsed time since the task was created.
You can calculate how many percent of CPU time task has used:
100 * (total_used_cputime / total_used_time_hz) / total_elapsed_time
Please remember that this number doesn't mean the percentage
of CPU time the task has used from all used CPU time. It's
the percentage of CPU time the task has used from the total
available CPU time.
TASK_CPU_USAGEF_LASTSEC_IMPLEMENTED
CPU time used by this task during last second. The
cpu_usage->used_cputime_lastsec_hz is the number of clock
ticks during one second. The cpu_usage->used_cputime_lastsec
is the number of ticks used. To calculate the percentage
of CPU time used:
100 * used_cputime_lastsec / used_cputime_lastsec_hz
TASK_CPU_USAGEF_RECENT_IMPLEMENTED
The cpu_usage->recent_used_cputime is a decaying average of
recent CPU usage. In Executive this is for the last minute.
The time in seconds is stored in cpu_usage->recent_seconds.
You can calculate recent CPU usage percentage in this way:
100 * recent_used_cputime / recent_used_cputime_hz
TASK_CPU_USAGEF_IVVOCSW_IMPLEMENTED
Some servers can also keep a count of the number of context
switches. A context switch happens when one task is switched
to another. The cpu_usage->involuntary_csw field indicates the
total number of involuntary context switches for the specified
task and the cpu_usage->voluntary_csw field indicates the total
numnber of voluntary context switches.
Involuntary context switch happens when the CPU is taken
away from a task that has not finished using it. This happens
when a higher priority task becomes ready to run.
Voluntary context switch happens when task calls Wait() and
a lower priority task gets CPU time.
TASK_CPU_USAGEF_TOTALCSW_IMPLEMENTED
In some implementations only the total number of context switches
is available. The cpu_usage->total_csw is just involuntary context
switches plus voluntary context switches, if specific information
is available.
TASK_CPU_USAGEF_IVVOCSW_LASTSEC_IMPLEMENTED
TASK_CPU_USAGEF_TOTALCSW_LASTSEC_IMPLEMENTED
Like above, but for the last second.
When using these numbers, do all calculations in 32-bits.
INPUTS
sysinfo - structure returned by InitSysinfo()
cpu_usage - structure defined in <libraries/sysinfo.h>
task - task address, NULL for current task
RESULT
success - 0 for success, 1 for error
BUGS
SEE ALSO
GetCpuUsage(), <libraries/sysinfo.h>
sysinfo.library/InitSysinfo sysinfo.library/InitSysinfo
NAME
InitSysinfo - Initialize the sysinfo.library
SYNOPSIS
sysinfo InitSysinfo(void);
D0
struct sysinfo *InitSysinfo(void);
FUNCTION
This function will initialize the sysinfo.library and possibly
make a connection to the server task. It returns a sysinfo structure
which you need when requesting information. The structure is read-
only and it's size may grow in later versions of the library.
INPUTS
None
RESULT
sysinfo - structure defined in <libraries/sysinfo.h>
BUGS
SEE ALSO
FreeSysinfo(), <libraries/sysinfo.h>
sysinfo.library/RemoveNotify sysinfo.library/RemoveNotify
NAME
RemoveNotify - Remove a notification request
SYNOPSIS
RemoveNotify(sysinfo,sysinfo_notify);
A0 A0
void RemoveNotify(struct sysinfo *, struct sysinfo_notify);
FUNCTION
Remove the notification request added with AddNotify(). This function
will internally make sure that you won't get any more notification
messages and it will clean up the queued messages if any. It will
also clear the signal if it was allocated.
INPUTS
sysinfo - sysinfo structure returned by InitSysinfo()
sysinfo_notify - the sysinfo_notify structure you got from AddNotify()
RESULT
None
BUGS
SEE ALSO
AddNotify(), <libraries/sysinfo.h>
sysinfo.library/SetNice sysinfo.library/SetNice
NAME
SetNice - set internal priority, nice-value
SYNOPSIS
success = SetNice(sysinfo, which, who, nice)
D0 A0 D0 D1 D2
int SetNice(struct sysinfo *, int, int, int);
FUNCTION
Set a nice-value for a process or group of processes.
See GetNice() for more information.
INPUTS
sysinfo - structure returned by InitSysinfo()
which - which processes are affected
who - depends on which-field, 0 means current process, PGRP, user or task
nice - change nice to this value
RESULT
success - 0 if there is no error, or -1 if there is, in which case
the error is in sysinfo->errno:
WHICH_ESRCH No process was located using the which and who values
specified.
WHICH_EINVAL Which was not one of PRIO_PROCESS, PRIO_PGRP,
PRIO_USER or PRIO_TASK, or that value is not supported.
Some implementations may returns one of these:
WHICH_EPERM A process was located, but neither its effective nor real
user ID matched the effective user ID of the caller.
WHICH_EACCES A non super-user attempted to lower a process priority.
NOTES
The name of this function should have been SetPriority() like in
Un*x, but it might have been confused with Exec priorities.
BUGS
SEE ALSO
<libraries/sysinfo.h>